package com.dly.blog.controller;

import com.dly.blog.domain.vo.menu.MenuTreeVO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dly.blog.controller.BaseController;
import lombok.AllArgsConstructor;
import com.dly.blog.domain.vo.menu.MenuVO;
import com.dly.blog.domain.ro.menu.MenuPageRO;
import com.dly.blog.domain.ro.menu.MenuAddRO;
import com.dly.blog.domain.ro.menu.MenuEditRO;
import com.dly.blog.service.MenuService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.dly.blog.domain.vo.PageVO;
import com.dly.blog.msg.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.List;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author DLY
 * @since 2024-11-04 17:08:58
 */
@Tag(name = "菜单表相关")
@AllArgsConstructor
@RestController
@RequestMapping("/user/menu")
public class MenuController extends BaseController {

    private final MenuService menuService;

    @GetMapping(value = "/tree_all")
    @Operation(summary = "获取所有菜单的树状数据")
    public ResponseEntity<R<List<MenuTreeVO>>> getAllMenu(){
        return operate(()-> this.successDate(menuService.getAllMenu()));
    }


    @PostMapping(value = "/page")
    @Operation(summary = "分页获取菜单表信息")
    public ResponseEntity<R<PageVO<MenuVO>>> getMenuPage(@RequestBody MenuPageRO menuPageRO){
        return operate(()-> this.successDate(menuService.getMenuPage(menuPageRO)));
    }

    @PostMapping(value = "/add")
    @Operation(summary = "添加菜单表信息")
    public ResponseEntity<R<Void>> addMenu(@RequestBody MenuAddRO menuAddRO){
        menuService.addMenu(menuAddRO);
        return operate(this::success);
    }

    @PostMapping(value = "/edit")
    @Operation(summary = "修改菜单表信息")
    public ResponseEntity<R<Void>> editMenu(@RequestBody MenuEditRO menuEditRO){
        menuService.editMenu(menuEditRO);
        return operate(this::success);
    }

    @PostMapping(value = "/get/{id}")
    @Operation(summary = "获取菜单表信息")
    public ResponseEntity<R<MenuVO>> getMenu(@PathVariable(value = "id") String id){
        return operate(()-> this.successDate(menuService.getMenu(id)));
    }

    @PostMapping(value = "/remove/{ids}")
    @Operation(summary = "删除菜单表信息")
    public ResponseEntity<R<Void>> removeMenu(@PathVariable(value = "ids") String[] ids){
        menuService.removeMenu(ids);
        return operate(this::success);
    }

}
